﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using PMC.Plugins;

namespace PMC.Scripts
{
    public class ScriptInfo
    {
        protected static readonly ScriptInfoAttribute notFoundAttribute = new ScriptInfoAttribute("Not available", "Not available", "Not available", "Not available", "en");

        /// <summary>
        /// Info about the scripts
        /// </summary>
        protected ScriptInfoAttribute[] scriptInfos;
        /// <summary>
        /// Gets info about the current script
        /// </summary>
        /// <param name="culture">Culture to match</param>
        /// <returns>Matching script otherwise first</returns>
        public virtual ScriptInfoAttribute GetScriptInfoByCulture(CultureInfo culture)
        {
            if (scriptInfos == null)
                scriptInfos = (ScriptInfoAttribute[])GetType().GetCustomAttributes(typeof(ScriptInfoAttribute), true);

            if (scriptInfos.Length == 0)
                return notFoundAttribute;

            foreach (var scriptInfo in scriptInfos)
            {
                if (culture.TwoLetterISOLanguageName == scriptInfo.CultureInfo)
                    return scriptInfo;
            }
            return scriptInfos[0];
        }
    }
}
